<?php
	include_once('class/jenis.php');
	
	$jenis=new Jenis();
	$data_jns=$jenis->getJenis();
	
	if(isset($_SESSION['login']))
	{
		include_once('class/biodata.php');
		$biodata = new Biodata();
		$id_username=$_SESSION['login'];
		$data=$biodata->getBiodata($id_username);
	}
	
	if(isset($_POST['simpan_biodata']))
	{
		include_once('class/biodata.php');
		$biodata = new Biodata();
		$nama=$_POST['nama'];
		$alamat=$_POST['alamat'];
		$telp=$_POST['telp'];
		$fax=$_POST['fax'];
		$email=$_POST['email'];
		$id_jns_anggota=$_POST['id_jns_anggota'];
		$id_username=$_SESSION['login'];
		
		if(empty($nama) || empty($alamat) || empty($telp) || empty($email))
		{
			$error="Field bertanda bintang harus diisi";
		}
		elseif(!filter_var($email,FILTER_VALIDATE_EMAIL))
		{
			$error="Alamat email tidak valid";
		}
		else
		{
			$cek=$biodata->getBiodata($id_username);
			if($cek==0)
			{
				$isi=$biodata->createBiodata($nama, $alamat, $telp, $fax, $email, $id_jns_anggota, $id_username);
				if($isi==1)
				{
					$success="Anda Sudah Terdaftar Silahkan lengkapi biodata dan berbelanja";
				}
			}
			else
			{
				$error="Biodata Sudah diisi";
			}
		}
		
	}
	
	if(isset($_POST['simpan_ubah']))
	{
		include_once('class/biodata.php');
		$biodata = new Biodata();
		$nama=$_POST['nama_ubah'];
		$alamat=$_POST['alamat_ubah'];
		$telp=$_POST['telp_ubah'];
		$fax=$_POST['fax_ubah'];
		$email=$_POST['email_ubah'];
		$id_jns_anggota=$_POST['id_jns_anggota_ubah'];
		$id_biodata=$_POST['id_ubah'];
		$id_username=$_SESSION['login'];
		
		if(empty($nama) || empty($alamat) || empty($telp) || empty($email))
		{
			$error="Field bertanda bintang harus diisi";
		}
		elseif(!filter_var($email,FILTER_VALIDATE_EMAIL))
		{
			$error="Alamat email tidak valid";
		}
		else
		{
			$cek=$biodata->getBiodata($id_username);
			if($cek!=0)
			{
				$ubah=$biodata->updateBiodata($id_biodata, $nama, $alamat, $telp, $fax, $email, $id_jns_anggota);
				if($ubah==1)
				{	
					header("location: biodata.php");
					$success="Biodata berhasil dirubah";
				}
			}
			else
			{
				$error="Biodata Tidak ada";
			}
		}
		
	}

?>